home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2008 September
/
PCWorld_2008-09_cd.bin
/
v cisle
/
sadanastroju
/
wot-20080519-fx.xpi
/
chrome
/
wot.jar
/
content
/
popup.js
< prev
next >
Wrap
Text File
|
2008-05-08
|
10KB
|
399 lines
/*
popup.js
Copyright ⌐ 2006, 2007 Against Intuition, Inc. <info@mywot.com>
*/
const WOT_POPUP_LAYER =
"<div id=\"wot-logo\"></div>" +
"<div id=\"wot-ratings\">" +
"<div id=\"wot-r0-stack\" class=\"wot-stack\">" +
"<div id=\"wot-r0-header\" class=\"wot-header\">WOT_POPUP_TEXT_0</div>" +
"<div id=\"wot-r0-rep\" class=\"wot-rep\"></div>" +
"<div id=\"wot-r0-cnf\" class=\"wot-cnf\"></div>" +
"</div>" +
"<div id=\"wot-r1-stack\" class=\"wot-stack\">" +
"<div id=\"wot-r1-header\" class=\"wot-header\">WOT_POPUP_TEXT_1</div>" +
"<div id=\"wot-r1-rep\" class=\"wot-rep\"></div>" +
"<div id=\"wot-r1-cnf\" class=\"wot-cnf\"></div>" +
"</div>" +
"<div id=\"wot-r2-stack\" class=\"wot-stack\">" +
"<div id=\"wot-r2-header\" class=\"wot-header\">WOT_POPUP_TEXT_2</div>" +
"<div id=\"wot-r2-rep\" class=\"wot-rep\"></div>" +
"<div id=\"wot-r2-cnf\" class=\"wot-cnf\"></div>" +
"</div>" +
"<div id=\"wot-r4-stack\" class=\"wot-stack\">" +
"<div id=\"wot-r4-header\" class=\"wot-header\">WOT_POPUP_TEXT_4</div>" +
"<div id=\"wot-r4-rep\" class=\"wot-rep\"></div>" +
"<div id=\"wot-r4-cnf\" class=\"wot-cnf\"></div>" +
"</div>" +
"</div>";
const WOT_POPUP_STYLE =
"@import \"chrome://wot/skin/include/popup.css\";";
var wot_popup =
{
offset: 15,
height: 235,
width: 137,
ratingheight: 52,
areaheight: 214,
barsize: 20,
offsetheight: 0,
id: "wot-popup-layer-" + Date.now().toString(),
init: function()
{
try {
window.addEventListener("load", function(e) {
wot_popup.load();
}, false);
window.addEventListener("unload", function(e) {
wot_popup.unload();
}, false);
} catch (e) {
dump("wot_popup.init: failed with " + e + "\n");
}
},
load: function()
{
try {
if (this.browser) {
return;
}
this.browser = document.getElementById("appcontent");
if (this.browser) {
this.browser.addEventListener("mouseover",
wot_popup.onmouseover, false);
}
} catch (e) {
dump("wot_popup.load: failed with " + e + "\n");
}
},
unload: function()
{
try {
if (this.browser) {
this.browser.removeEventListener("mouseover",
wot_popup.onmouseover, false);
this.browser = null;
}
} catch (e) {
dump("wot_popup.unload: failed with " + e + "\n");
}
},
add_popup: function(content)
{
try {
if (!wot_prefs.show_search_popup) {
return false;
}
if (!this.layer) {
this.layer = WOT_POPUP_LAYER;
this.layer = this.layer.replace(/WOT_POPUP_TEXT_0/g,
wot_util.getstring("rating_0") + ":");
this.layer = this.layer.replace(/WOT_POPUP_TEXT_1/g,
wot_util.getstring("rating_1") + ":");
this.layer = this.layer.replace(/WOT_POPUP_TEXT_2/g,
wot_util.getstring("rating_2") + ":");
this.layer = this.layer.replace(/WOT_POPUP_TEXT_4/g,
wot_util.getstring("rating_4") + ":");
}
if (content.getElementById(this.id)) {
return true;
}
var layer = content.createElement("div");
layer.setAttribute("id", this.id);
layer.setAttribute("class", "wot-popup-layer");
layer.setAttribute("style", "display: none;");
layer.innerHTML = this.layer;
var style = content.createElement("style");
style.setAttribute("type", "text/css");
style.innerHTML = WOT_POPUP_STYLE;
var body = content.getElementsByTagName("body");
var head = content.getElementsByTagName("head");
if (!body || !body.length || !head || !head.length) {
return false;
}
body[0].appendChild(layer);
head[0].appendChild(style);
return true;
} catch (e) {
dump("wot_popup.add_popup: failed with " + e + "\n");
}
return false;
},
elem_pos_x: function(elem)
{
var curtop = 0;
try {
if (elem.offsetParent) {
while (elem.offsetParent) {
curtop += elem.offsetLeft;
elem = elem.offsetParent;
}
} else if (elem.x) {
curtop += elem.x;
}
} catch (e) {
dump("wot_popup.elem_pos_x: failed with " + e + "\n");
}
return curtop;
},
elem_pos_y: function(elem)
{
var curtop = 0;
try {
if (elem.offsetParent) {
while (elem.offsetParent) {
curtop += elem.offsetTop;
elem = elem.offsetParent;
}
} else if (elem.y) {
curtop += elem.y;
}
} catch (e) {
dump("wot_popup.elem_pos_x: failed with " + e + "\n");
}
return curtop;
},
loadlayer: function(content, layer, target)
{
try {
var status = wot_cache.get(target, "status");
if (status != WOT_QUERY_OK && status != WOT_QUERY_LINK) {
return false;
}
var cls = layer.getAttribute("class");
if (wot_prefs.accessible) {
if (!cls || !cls.length) {
cls = "accessible";
} else if (cls.indexOf("accessible") < 0) {
cls += " accessible";
}
layer.setAttribute("class", cls);
} else if (cls && cls.indexOf("accessible") >= 0) {
cls = cls.replace(/accessible/g, "");
layer.setAttribute("class", cls);
}
for (var i = 0; i < WOT_APPLICATIONS; ++i) {
var rep = content.getElementById("wot-r" + i + "-rep");
var cnf = content.getElementById("wot-r" + i + "-cnf");
if (!rep || !cnf) {
continue;
}
var r = wot_cache.get(target, "reputation_" + i);
var c = wot_cache.get(target, "confidence_" + i);
if (r >= WOT_MIN_REPUTATION_5) {
rep.setAttribute("reputation", 5);
} else if (r >= WOT_MIN_REPUTATION_4) {
rep.setAttribute("reputation", 4);
} else if (r >= WOT_MIN_REPUTATION_3) {
rep.setAttribute("reputation", 3);
} else if (r >= WOT_MIN_REPUTATION_2) {
rep.setAttribute("reputation", 2);
} else if (r >= 0) {
rep.setAttribute("reputation", 1);
} else {
rep.setAttribute("reputation", 0);
}
if (c >= WOT_MIN_CONFIDENCE_5) {
cnf.setAttribute("confidence", 5);
} else if (c >= WOT_MIN_CONFIDENCE_4) {
cnf.setAttribute("confidence", 4);
} else if (c >= WOT_MIN_CONFIDENCE_3) {
cnf.setAttribute("confidence", 3);
} else if (c >= WOT_MIN_CONFIDENCE_2) {
cnf.setAttribute("confidence", 2);
} else if (c >= WOT_MIN_CONFIDENCE_1) {
cnf.setAttribute("confidence", 1);
} else {
cnf.setAttribute("confidence", 0);
}
}
wot_popup.offsetheight = 0;
var bottom = content.getElementById("wot-r0-stack");
if (wot_prefs.show_application_1) {
bottom = content.getElementById("wot-r1-stack");
bottom.style.display = "block";
} else {
content.getElementById("wot-r1-stack").style.display = "none";
wot_popup.offsetheight -= wot_popup.ratingheight;
}
if (wot_prefs.show_application_2) {
bottom = content.getElementById("wot-r2-stack");
bottom.style.display = "block";
} else {
content.getElementById("wot-r2-stack").style.display = "none";
wot_popup.offsetheight -= wot_popup.ratingheight;
}
if (wot_prefs.show_application_4) {
bottom = content.getElementById("wot-r4-stack");
bottom.style.display = "block";
} else {
content.getElementById("wot-r4-stack").style.display = "none";
wot_popup.offsetheight -= wot_popup.ratingheight;
}
bottom.style.borderBottom = "0";
content.getElementById("wot-ratings").style.height =
wot_popup.offsetheight + wot_popup.areaheight + "px";
return true;
} catch (e) {
dump("wot_popup.loadlayer: failed with " + e + "\n");
}
return false;
},
hidelayer: function(content)
{
try {
var layer = content.getElementById(this.id);
if (layer && layer.style.display != "none") {
layer.style.display = "none";
}
} catch (e) {
dump("wot_popup.hidelayer: failed with " + e + "\n");
}
},
findelem: function(event)
{
try {
var elem = event.originalTarget;
var attr = null;
while (elem) {
if (elem.attributes) {
attr = elem.attributes.getNamedItem(wot_search.attribute);
if (attr && attr.nodeValue) {
break;
}
attr = null;
}
elem = elem.parentNode;
}
if (!elem || !attr) {
return null;
}
return elem;
} catch (e) {
dump("wot_popup.findelem: failed with " + e + "\n");
}
return null;
},
onmouseover: function(event)
{
try {
if (!wot_prefs.enabled || !wot_prefs.show_search_popup ||
!event || !event.view) {
return;
}
var content = event.view.document;
if (!content) {
return;
}
var layer = content.getElementById(wot_popup.id);
if (!layer) {
return;
}
var elem = wot_popup.findelem(event);
if (!elem) {
wot_popup.hidelayer(content);
return;
}
var attr = elem.attributes.getNamedItem(wot_search.attribute);
var target = attr.nodeValue;
if (layer.style.display == "block" &&
layer.getAttribute("target") == target) {
return;
}
layer.setAttribute("target", target);
if (!wot_popup.loadlayer(content, layer, target)) {
wot_popup.hidelayer(content);
return;
}
var popupheight = wot_popup.height + wot_popup.offsetheight;
layer.style.height = popupheight + "px";
layer.style.width = wot_popup.width + "px";
var height = event.view.innerHeight - wot_popup.barsize;
var width = event.view.innerWidth - wot_popup.barsize;
if (height < popupheight || width < wot_popup.width) {
wot_popup.hidelayer(content);
return
}
var vscroll = event.view.pageYOffset;
var hscroll = event.view.pageXOffset;
var y = wot_popup.elem_pos_y(elem);
var posy = wot_popup.offset + y + elem.offsetHeight;
var posx = wot_popup.offset + event.pageX;
if (posy + popupheight > height + vscroll) {
posy = y - popupheight - wot_popup.offset;
}
if (posx - hscroll < 0) {
posx = hscroll;
} else if ((posx + wot_popup.width) > (width + hscroll)) {
posx = width - wot_popup.width + hscroll;
}
layer.style.top = posy + "px";
layer.style.left = posx + "px";
layer.style.display = "block";
} catch (e) {
dump("wot_popup.onmouseover: failed with " + e + "\n");
}
}
};
wot_popup.init();